import {reactive} from "vue";
import type {PaginationProps} from "@pureadmin/table";

interface Pagination {
  total?: number;
  currentPage?: number;
  pageSizes?: number[];
  pageSize?: number;
  layout?: string;
}

/** 默认的分页参数 */
export const defaultPagination: PaginationProps = {
  total: 0,
  pageSize: 10,
  currentPage: 1,
  background: true
};

export const usePagination = (initialPagination: Pagination = {}) => {
  /** 合并分页参数 */
  const pagination = reactive({...defaultPagination, ...initialPagination});
  /** 改变当前页码 */
  const handleCurrentChange = (value: number) => {
    pagination.currentPage = value;
  };
  /** 改变页面大小 */
  const handleSizeChange = (value: number) => {
    pagination.pageSize = value;
  };

  return {pagination, handleCurrentChange, handleSizeChange};
};
